using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Colorprj
{
    public partial class frmChallanSelection : Form
    {
        List<string> aList = new List<string>();
        List<string> challanNoList = new List<string>();
        private int _valueFromParent;
        public int valueFromParent
        {
            set { _valueFromParent = value; }
        } 

        public frmChallanSelection()
        {
            InitializeComponent();

           // MessageBox.Show(_valueFromParent.ToString());

        }

        private void frmChallanSelection_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'colorPrjDataSet6.ChallanHead' table. You can move, or remove it, as needed.
            
            // TODO: This line of code loads data into the 'colorPrjChallanHead.ChallanHead' table. You can move, or remove it, as needed.
           // this.challanHeadTableAdapter.Fill(this.colorPrjChallanHead.ChallanHead);
            Challan.ChallanManager cm = new Colorprj.Challan.ChallanManager();  
            //if (ps.ShowDialog() == DialogResult.OK)
            //{

                //int ChallanId = Convert.ToInt16(ps.ItemToRead);


            List<Challan.ChallanHeadEntity> chList = cm.GetUnInvChallanList(_valueFromParent);
                //txtChallanHeadId.Text = ChallanId.ToString();
                //txtChallanNo.Text = phEntity.ChallanNo;
                //dtChallanDate.Value = phEntity.ChallanDate;
                //cboParty.SelectedValue = phEntity.BuyerId ;
                //txtTotal.Text = phEntity.TotalAmount.ToString();


            if (chList.Count>0) dataGridView1.RowCount = chList.Count;
                int row = 0;
                foreach (Challan.ChallanHeadEntity phEntity in chList)
                {

                    dataGridView1["ChallanNo", row].Value = phEntity.ChallanNo;
                    dataGridView1["ChallanId", row].Value = phEntity.ChallanHeadId;
                    dataGridView1["BuyerId", row].Value = phEntity.BuyerId;
                    //dataGridView1["ChallanDetId", row].Value = pdEntity.ChallanDetailId;
                    row++;

                }
 

        }
        public string ItemToRead
        {
            get
            {
                string retVal = string.Empty;  
                foreach (string  row in aList)
                {
                    retVal += ","+row;
                }
                if (!string.IsNullOrEmpty(retVal)) retVal = retVal.Substring(1);  
                return retVal;
            }
        }

        public string getChallanNos
        {
            get
            {
                string retVal = string.Empty;
                foreach (string row in challanNoList)
                {
                    retVal += "," + row;
                }
                if (!string.IsNullOrEmpty(retVal)) retVal = retVal.Substring(1);
                return retVal;
            }
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
           
            int rowCnt = 0;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                DataGridViewCheckBoxCell  oCell = row.Cells["chkChallan"] as DataGridViewCheckBoxCell;
                bool bChecked = (null != oCell && null != oCell.Value && true == (bool)oCell.Value);
                if (true == bChecked)
                {
                    aList.Add(row.Cells[1].Value.ToString());
                    challanNoList.Add(row.Cells[2].Value.ToString());
                }

                
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close(); 
        }
    }
}